<?php

/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/7/22
 * Time: 14:21
 */
namespace app\common\model;
use think\Model;
use DavidNineRoc\Qrcode\Factory;
use DavidNineRoc\Qrcode\QrCodePlus;
use Endroid\QrCode\QrCode;
use BaconQrCode\Common\ErrorCorrectionLevel;
class QrcodeToolModel extends Model
{
    public function logoMark($content,$logoPath,$logoWidth='',$logoHeight=''){
        $qrCode = new QrCode($content);
        $qrCode->setSize(300);

        $qrCode->setWriterByName('png');
        $qrCode->setMargin(10);
        $qrCode->setEncoding('UTF-8');
        $qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]);
        $qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]);
        $qrCode->setLogoPath($logoPath);
        if($logoWidth&&$logoHeight){
            $qrCode->setLogoSize($logoWidth,$logoHeight);
        }
        $qrCode->setRoundBlockSize(true);
        $qrCode->setValidateResult(false);
        $qrCode->setWriterOptions(['exclude_xml_declaration' => true]);

        header('Content-Type: '.$qrCode->getContentType());
        ob_end_clean();
        $file = tempDir(date('d')).'/'.randNameByTime().'.png';
         return    $qrCode->writeFile($file);
    }
}